<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>人员维护</title>
</head>

<body>
<div id="menu" style="height: 64%;overflow: scroll;width:20%">
	<ul id="UsersTree" class="ztree"></ul>
</div>
<div id="content" style="height: 500px">
<form id="form1" name="form1" action="" method="post">
		<div>
			用户姓名:<input type="text" id="userName1" name="userName1" value="${userName1 }" /> 
			用户账号:<input type="text" id="userNumber1" name="userNumber1" value="${userNumber1 }" />
			是否激活：<select id="attribute1" name="attribute1">
						<option value="">请选择</option>
						<option value="0">未激活</option>	
						<option value="1">已激活</option>
					</select>
					<script>
						jQuery("#attribute1").val('${attribute1}');
					</script>
			<input id="search1" style="display: none" type="button" value="查询" onclick="search()"/>
			<input id="new" style="display: none" type="button" value="新增" onclick="addNew()"/>
			<%-- <input type="button" value="新增临时" onclick="addNewTemp()"/>--%>
			<input id="delete" style="display: none" type="button" value="删除" onclick="deleteAll()"/>
			<input id="regist" style="display: none" type="button" value="激活" onclick="registAll()"/>
			<input type="hidden" id="userId" name="userId" />
			<input type="hidden" id="bloneto1" name="bloneto1" value="${bloneto }"/>
			<input type="hidden" id="userId1" name="userId1" value="${userId1 }"/>
			<input type="hidden" id="currentPageNo" name="currentPageNo" value="${currentPageNo}">
			<input type="hidden" id="perPageNumber" name="perPageNumber" value="${perPageNumber}">
		</div>
		<table id="mytable" cellspacing="0" summary="The technical specifications of the Apple PowerMac G5 series">  
		  <tr>
		  	<th><input type="checkbox" id="all" name="all"/></th> 
		    <th>序号</th> 
		    <th>姓名</th> 
		    <th>账号</th> 
		    <th>性别</th>
		    <th>出生日期</th>
		    <th>邮件</th>
		    <th>手机</th>
		    <th>状态</th>  
		    <th>操作</th> 
		  </tr> 
		  <c:forEach items="${users}" var="user" varStatus="i">
		  	<tr> 
		  		<td align="center"><input type="checkbox" id="selId" name="selId" value="${user.userId}" alt="${user.userName}"/></td> 
			   	<td>${i.index+1}</td>
			    <td><a href="javascript:void(0)" onclick="lookUser('${user.userId}')" >${user.userName}</a></td> 
			    <td>${user.userLogin}</td>
			    <td>${user.sex}</td> 
			    <td>${user.brithday}</td>
			    <%-- <td><fmt:formatDate value="${user.brithday}" type="date" pattern="yyyy-MM-dd HH:mm:ss"/></td> --%> 
			    <td>${user.email}</td> 
			    <td>${user.mobilephone}</td> 
			    <td>${user.attribute1==1?"已激活":"未激活"}</td>
			    <td><a name="delete1" style="display: none" href="javascript:void(0)" onclick="deleteOne('${user.userId}','${user.userName}')">删除</a>
			    	<a name="modify" style="display: none" href="javascript:void(0)" onclick="toUpdatePage('${user.userId}')">修改</a></td>
		  	</tr> 
		  </c:forEach>
		  
			</table> 
			 <div id="Pagination" ></div>
</table>

</form>
</div>
<script type="text/javascript">
var ctx = "${pageContext.request.contextPath}";
var page = "${currentPageNo}";
//初始化checkbox
jQuery("document").ready(function(){
	jQuery("#all").click(function(){
			var flag = document.getElementById("all").checked;
	   	 	jQuery("[name=selId]:checkbox").each(function() {
	        		jQuery(this).attr("checked", flag);
	   		});
   });
	$("#Pagination").paginate({
		count 		: '${count}',	//页数
		start 		: '${currentPageNo}',
		display     : 10,
		border					: true,
		border_color			: '#BEF8B8',
		text_color  			: '#68BA64',
		background_color    	: '#CAE8EA',	
		border_hover_color		: '#68BA64',
		text_hover_color  		: 'black',
		background_hover_color	: '#CAE8EA', 
		rotate      : false,
		images		: false,
		mouse		: 'press',
		onChange     			: function(page){
									var formObj = document.getElementById("form1");
									$("#currentPageNo").val(page);
									formObj.action=ctx+'/ufmUser/findAll';
									formObj.submit();
								  }
	});
	//初始化页面按钮
	//allRights
	
	var setting6 = {
			async: {
				enable: true,
				url:"${pageContext.request.contextPath}/rights/getUserAndDept",
				autoParam:["id", "level"]
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			callback: {
				onClick:getDeptId
			}
		};
	$.fn.zTree.init($("#UsersTree"), setting6);
	
	if($.inArray("人员维护_删除", allRights)>=0){
		   $("#delete").show();
		   $("a[name='delete1']").show();
	   }
	   if($.inArray("人员维护_新增", allRights)>=0){
		   $("#new").show();
	   }
	   if($.inArray("人员维护_修改", allRights)>=0){
		   $("a[name='modify']").show();
	   }
	   if($.inArray("人员维护_查询", allRights)>=0){
		   $("#search1").show();
	   }
	   if($.inArray("人员维护_激活", allRights)>=0){
		   $("#regist").show();
	   }
	   
});
function getDeptId(event, treeId, treeNode){
	var formObj = document.getElementById("form1");
	$("#currentPageNo").val(1);
	if(treeNode.isParent){
		formObj.action=ctx+'/ufmUser/findAll?bloneto1='+treeNode.id+'&userId1=';
		formObj.submit();
	}else{
		var id = treeNode.id;
		id = id.substring(1);
		formObj.action=ctx+"/ufmUser/findAll?bloneto1=&userId1="+id;
		formObj.submit();
	}
}
function addNew(){
	var formObj = document.getElementById("form1");
	formObj.action=ctx+'/ufmUser/addUser';
	formObj.submit();
}

function addNewTemp(){
	var formObj = document.getElementById("form1");
	formObj.action=ctx+'/ufmUser/addNewTemp';
	formObj.submit();
}

function search(){
	var formObj = document.getElementById("form1");
	$("#currentPageNo").val(1);
	formObj.action=ctx+'/ufmUser/findAll';
	formObj.submit();
}

function lookUser(userId){
	var formObj = document.getElementById("form1");
	$('#userId').val(userId);
	formObj.action=ctx+'/ufmUser/lookUser';
	formObj.submit();
}

function toUpdatePage(userId){
	var formObj = document.getElementById("form1");
	$('#userId').val(userId);
	formObj.action=ctx+'/ufmUser/toUpdatePage';
	formObj.submit();
}

function deleteAll(){
	var flag = true;
	var formObj = document.getElementById("form1");
	$('input[name="selId"]:checked').each(function(){    
		if($(this).attr("alt") == "admin"){
			flag = false;
		}
	});
	if(flag){
		if(window.confirm("确认删除用户?")){
			var chk_value =[];
			$('input[name="selId"]:checked').each(function(){    
					chk_value.push(jQuery(this).val());
			});
			var selIds = chk_value.join();
			if(selIds==''){
				alert("请选择要删除的用户!");
				return;
			}
			var url = ctx+'/ufmUser/deleteAll';
			url+= '?selIds='+selIds;
			
			formObj.action=url;
			formObj.submit();
			
		}
	}else{
		alert("不能删除admin用户");
	}
}

function registAll(){
	var formObj = document.getElementById("form1");
	if(window.confirm("确认激活用户?")){
		var chk_value =[];
		$('input[name="selId"]:checked').each(function(){    
				chk_value.push(jQuery(this).val());
		});
		var selIds = chk_value.join();
		if(selIds==''){
			alert("请选择要激活的用户!");
			return;
		}
		var url = ctx+'/ufmUser/registAll';
		url+= '?selIds='+selIds;
		
		formObj.action=url;
		formObj.submit();
	}
}

function deleteOne(id,name){
	var formObj = document.getElementById("form1");
	if(name == "admin"){
		alert("不能删除admin用户");
	}else{
		if(confirm('确定要删除吗?'))
		{
			var url = ctx+'/ufmUser/deleteAll';
			url+= '?selIds='+id;
			
			formObj.action=url;
			formObj.submit();
			}
		return false;
	}
}
</script>
</body>
</html>
